package j20251101;

import java.util.concurrent.atomic.AtomicBoolean;

public class Demo1 {
    private AtomicBoolean locked = new AtomicBoolean(false);

    public void lock() {
        // 自旋等待
        while (!locked.compareAndSet(false, true)) {
                // 空循环，不做任何操作
        }
    }

    public void unlock() {
        locked.set(false);
    }
}
